#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0, right = 0, sum = 0, len = 0;
        while (right < nums.size())
        {
            sum += nums[right++];//进窗口
            while (sum >= target)//判断
            {
                if (len == 0)
                    len = right - left;
                else len = len < right - left ? len : right - left;//更新结果
                left++;
                sum -= nums[left - 1];//出窗口
            }
        }
        return len;
    }
};
